﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>

<!DOCTYPE html>
<html>
@* <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.9.18/dist/css/layui.css" rel="stylesheet">
</head> *@
<body>
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <div class="layui-form-item">


                <div class="layui-form-item">



                    <label class="layui-form-label">联系人</label>
                    <div class="layui-input-inline layui-input-wrap">
                        <input type="text" id="bank" class="layui-input demo-phone">
                    </div>


                    <label class="layui-form-label">职务</label>
                    <div class="layui-input-inline layui-input-wrap">
                        <input type="text" id="bank" class="layui-input demo-phone">
                    </div>
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label">地址</label>
                    <div class="layui-input-block layui-input-wrap">
                        <div class="layui-input-inline">
                            <select id="provinceId" lay-filter="provincet">
                                <option value="">请选择</option>
                            </select>
                            <select id="directlyId" lay-filter="city">
                                <option value="">请选择</option>
                            </select>
                            <select id="countyId" lay-filter="directly">
                                <option value="">请选择</option>
                            </select>
                            <input type="text" id="bank" class="layui-input demo-phone">
                        </div>
                       
                       
                    </div>
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label">电话</label>
                    <div class="layui-input-inline layui-input-wrap">
                        <input type="text" id="bphone" lay-verify="required" autocomplete="off" lay-reqtext="请输入用户名" lay-affix="clear" class="layui-input demo-phone">
                    </div>

                    <label class="layui-form-label">手机号</label>
                    <div class="layui-input-inline layui-input-wrap">
                        <input type="text" id="bCard" lay-verify="required" autocomplete="off" lay-reqtext="请输入用户名" lay-affix="clear" class="layui-input demo-phone">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">邮编</label>
                    <div class="layui-input-inline layui-input-wrap">
                        <input type="text" id="" lay-verify="required" autocomplete="off" lay-reqtext="请输入用户名" lay-affix="clear" class="layui-input demo-phone">
                    </div>
                    <label class="layui-form-label">邮箱</label>
                    <div class="layui-input-inline layui-input-wrap">
                        <input type="text" id="" lay-verify="required" autocomplete="off" lay-reqtext="请输入用户名" lay-affix="clear" class="layui-input demo-phone">
                    </div>

                   
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">账户属性</label>
                    <div class="layui-input-inline layui-input-wrap">
                        <input type="radio" name="battribute" value="公司" title="公司">
                        <input type="radio" name="battribute" value="个人" title="个人">
                    </div>

                    
                </div>


            </div>

            <div class="layui-form-item">
                <button type="button" class="layui-btn" lay-submit lay-filter="demo1">保存</button>

            </div>
        </div>
    </form>

    <!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
    @*  <script src="//unpkg.com/layui@2.9.18/dist/layui.js"></script> *@
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=rp5j6DYVV8tDQoOMrbQgAFxrAwnKvcWM"></script>
</body>

</html>

<script>
    layui.use(function () {
        var form = layui.form;
        var layer = layui.layer;;


        $(function () {
            bangsheng();
        })


        //省
        function bangsheng() {
            $.ajax({
                url: "http://localhost:5123/api/Regions/ProvinceQuerys",
                data: JSON.stringify({}),
                type: "post",
                async: false,
                dataType: "json",
                contentType: "application/json",
                success: res => {
                    console.log(res)
                    $.each(res.data, function () {
                        $("#provinceId").append(`<option value="${this.provinceId}">${this.provinceName}</option>`);
                    })
                    form.render('select'); // 重新渲染下拉框
                }

            })
        }
        var provincetId1 = 0;
        var cityid = 0;
        form.on('select(provincet)', function (data) {
            provincetId1 = data.value;
            console.log(provincetId1)
            $("#directlyId").empty();
            $("#directlyId").append(`<option value="">请选择</option>`);
            $("#countyId").empty();
            $("#countyId").append(`<option value="">请选择</option>`);
            bangshi()

        });
        form.on('select(city)', function (data) {
            cityid = data.value;
            console.log(provincetId1)
            $("#countyId").empty();
            $("#countyId").append(`<option value="">请选择</option>`);
            bangxian();

        });

        //市
        function bangshi() {
            var provinceId = $("#provinceId").val();
            $.ajax({
                url: "http://localhost:5123/api/Regions/CityQuerys",
                data: JSON.stringify({ provinceId: provincetId1 }),
                type: "post",
                async: false,
                dataType: "json",
                contentType: "application/json",
                success: res => {

                    console.log(res.data)
                    $.each(res.data, function () {

                        $("#directlyId").append(`<option value="${this.directlyId}">${this.directlyName}</option>`);
                    })
                    form.render('select'); // 重新渲染下拉框
                }

            })
        }
        //县
        function bangxian() {
            var directlyId = $("#directlyId").val();
            $.ajax({
                url: "http://localhost:5123/api/Regions/CountyQuerys",
                data: JSON.stringify({ directlyId: cityid }),
                type: "post",
                async: false,
                dataType: "json",
                contentType: "application/json",
                success: res => {

                    $.each(res.data, function () {
                        $("#countyId").append(`<option value="${this.countyId}">${this.countyName}</option>`);
                    })
                    form.render('select'); // 重新渲染下拉框
                }

            })
        }



        form.on('submit(demo1)', function (d) {
            var data = {
                vendorcontactName: $("#vendorcontactName").val(),
                vendorcontactWork: $("#vendorcontactWork").val(),
                contactAdress: $("#contactAdress").val(),
                provinceId: $("#provinceId").val(),
                vendorcontactPhone: $("#vendorcontactPhone").val(),
                contactPhone: $("#contactPhone").val(),
                vendorcontactEamil: $("#vendorcontactEamil").val(),
                contactEamil: $("#contactEamil").val(),
                isXuan: $("#isXuan").val(),
                vendorId: $("#vendorId").val(),
            }

            $.ajax({
                url: "http://localhost:5269/api/Vendor/CreateVendorcontact",
                type: 'post',
                data: JSON.stringify(data),
                dataType: "json",
                contentType: "application/json",
                success: res => {
                    if (res.code == 0) {
                        layer.msg('添加成功')
                    }
                    else {
                        layer.msg('保存失败')
                    }
                }
            })
            return false; // 阻止默认 form 跳转
        });





    });



</script>
